package com.rollCall.controller.app;

import cn.hutool.core.util.StrUtil;
import com.rollCall.common.constant.MessageConstant;
import com.rollCall.entity.vo.StudentLoginVo;
import com.rollCall.entity.vo.StudentVo;
import com.rollCall.entity.result.Result;
import com.rollCall.service.app.AppStudentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author LiZhiHan
 * @date 2025/2/28
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin
public class AppStudentController {
	private final AppStudentService appStudentService;

	/**
	 * 学生登录
	 */
	@PostMapping("/login")
	public Result<String> login(@RequestBody StudentLoginVo studentLoginVo){
		String token = appStudentService.login(studentLoginVo);
		return StrUtil.isBlank(token) ? Result.error(MessageConstant.PASSWORD_ERROR) : Result.success(token);
	}

	/**
	 * 查看我的信息
	 */
	@GetMapping("myInfo")
	public Result<StudentVo> myInfo(){
		StudentVo studentVo = appStudentService.myInfo();
		return Result.success(studentVo);
	}

}
